package com.iting.transcationdemo.service.impl;


import com.iting.transcationdemo.bean.User;
import com.iting.transcationdemo.dao.UserDao;
import com.iting.transcationdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

/**
 * @author iting Nie
 * @version 1.1
 * @create 2021/11/13
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
	UserDao userDao;
    @Override
    public int add(User user) throws SQLException {
        int add = userDao.add(user);
        return add;
        // System.out.println(userDao);
        // return 0;
    }
    @Override
    @Transactional
    public void traceTransactionalAndErr(int from, int to, int age) throws SQLException {
        userDao.update(from,-age);
        System.out.println(3/0);
        userDao.update(to,age);
    }
	@Override
	@Transactional
	public void traceTransactionalAndErrAndPrivate(int from, int to, int age) throws SQLException {
		userDao.update(from,-age);
		System.out.println(3/0);
		userDao.update(to,age);
	}
	@Override
	@Transactional
	public void traceTransactionalAndNoErr(int from, int to, int age) throws SQLException {
		userDao.update(from,-age);
		userDao.update(to,age);
	}
	@Override
	// @Transactional
	public void traceWithoutTransactionalAndNoErr(int from, int to, int age) throws SQLException {
		userDao.update(from,-age);
		userDao.update(to,age);
	}
	@Override
	// @Transactional
	public void traceWithoutTransactionalAndErr(int from, int to, int age) throws SQLException {
		userDao.update(from,-age);
		System.out.println(3/0);
		userDao.update(to,age);
	}


	@Override
    public int delete(int id) throws SQLException {
        return 0;
    }

    @Override
    public int update(User user) throws SQLException {
        return 0;
    }

    @Override
    public List<User> select() throws SQLException {
        return null;
    }

}
